<?php

class Upload extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->helper(array('form', 'url'));
	}

	function index()
	{
		$this->load->view('upload_form', array('error' => ' ' ));
	}

	function do_upload()
	{
		$config['upload_path'] = './uploads/';
		$config['allowed_types'] = 'jpeg|jpg|gif|png';
		$config['max_size'] = '1024';

		$this->load->library('upload', $config);
		
		$field_name = "file";
		
		if ( ! $this->upload->do_upload($field_name))
		{
			$error = array('error' => $this->upload->display_errors());

			$this->load->view('upload_form', $error);
		}	
		else
		{
			$data = array('upload_data' => $this->upload->data());

			$this->load->view('upload_success', $data);
		}
	}
	
	function crop_image()
	{	
		
		
		$config['image_library'] = 'gd2';
		$config['source_image'] = './uploads/' . 'Lighthouse.jpg';
		$config['create_thumb'] = TRUE;
		$config['maintain_ratio'] = TRUE;
		$config['width'] = 500;
		$config['height'] = 500;
		
		$this->load->library('image_lib', $config);	

		if ( ! $this->image_lib->crop())
		{
			echo $this->image_lib->display_errors();
		}
	
		echo "Crop successful!";
		
		$this->image_lib->clear();
	}
	 
	
}
?>